(function () {
  class Animal {
    name: string;
    constructor(theName: string) {
      this.name = theName;
    }
    sayHello() {
      console.log("动物在叫");
    }
  }

  class Dog extends Animal {
    age: number;
    constructor(name: string, age: number) {
      // 在子类中写了构造函数，在子类的构造函数中必须调用super()，否则会报错
      // super代表当前类的父类
      super(name); // 调用父类的构造函数
      this.age = age;
    }
    sayHello(): void {
      super.sayHello(); // 调用父类的sayHello方法
    }
  }

  const dog = new Dog("旺财", 4);
  dog.sayHello();
})();
